﻿Imports System.Data.SqlClient

Public Class clsLiquidacion
    Private mintIdLiquidacion As Integer
    Private mdatFecha As Date
    Private mintIdLiquidador As Integer
    Private mstrCodigoLiquidador As String
    Private mstrNombreLiquidador As String
    Private mintIdOperador As Integer
    Private mstrCodigoOperador As String
    Private mstrNombreOperador
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdRuta As Integer
    Private mstrNombreRuta As String
    Private mintTipoLiquidacion As Integer
    Private mstrSerie As String
    Private mdblNumeracionInicial As Double
    Private mdblNumeracionFinal As Double
    Private mdblTotalBoletos As Double
    Private mdblPreferencial As Double
    Private mdblGeneral As Double
    Private mdblIngresoPreferencial As Double
    Private mdblIngresoGeneral As Double
    Private mdblVueltas As Double
    Private mdblLiquidacion As Double
    Private mdblImporte01 As Double
    Private mdblImporte02 As Double
    Private mdblImporte03 As Double
    Private mdblImporte04 As Double
    Private mdblImporte05 As Double
    Private mstrTexto01 As String
    Private mstrTexto02 As String
    Private mstrTexto03 As String
    Private mstrTexto04 As String
    Private mstrTexto05 As String
    Public Property IdLiquidacion() As Integer
        Get
            Return mintIdLiquidacion
        End Get
        Set(ByVal value As Integer)
            mintIdLiquidacion = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property IdLiquidador() As Integer
        Get
            Return mintIdLiquidador
        End Get
        Set(ByVal value As Integer)
            mintIdLiquidador = value
        End Set
    End Property
    Public Property CodigoLiquidador() As String
        Get
            Return mstrCodigoLiquidador
        End Get
        Set(value As String)
            mstrCodigoLiquidador = value
        End Set
    End Property
    Public Property NombreLiquidador() As String
        Get
            Return mstrNombreLiquidador
        End Get
        Set(ByVal value As String)
            mstrNombreLiquidador = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property CodigoOperaor() As String
        Get
            Return mstrCodigoOperador
        End Get
        Set(value As String)
            mstrCodigoOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property

    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property

    Public Property IdRuta() As Integer
        Get
            Return mintIdRuta
        End Get
        Set(ByVal value As Integer)
            mintIdRuta = value
        End Set
    End Property
    Public Property NombreRuta() As String
        Get
            Return mstrNombreRuta
        End Get
        Set(ByVal value As String)
            mstrNombreRuta = value
        End Set
    End Property
    Public Property TipoLiquidacion() As Integer
        Get
            Return mintTipoLiquidacion
        End Get
        Set(ByVal value As Integer)
            mintTipoLiquidacion = value
        End Set
    End Property
    Public Property Serie() As String
        Get
            Return mstrSerie
        End Get
        Set(ByVal value As String)
            mstrSerie = value
        End Set
    End Property

    Public Property NumeracionInicial() As Double
        Get
            Return mdblNumeracionInicial
        End Get
        Set(ByVal value As Double)
            mdblNumeracionInicial = value
        End Set
    End Property
    Public Property NumeracionFinal() As Double
        Get
            Return mdblNumeracionFinal
        End Get
        Set(ByVal value As Double)
            mdblNumeracionFinal = value
        End Set
    End Property
    Public Property TotalBoletos() As Double
        Get
            Return mdblTotalBoletos
        End Get
        Set(ByVal value As Double)
            mdblTotalBoletos = value
        End Set
    End Property
    Public Property Preferencial() As Double
        Get
            Return mdblPreferencial
        End Get
        Set(ByVal value As Double)
            mdblPreferencial = value
        End Set
    End Property

    Public Property General() As Double
        Get
            Return mdblGeneral
        End Get
        Set(ByVal value As Double)
            mdblGeneral = value
        End Set
    End Property
    Public Property IngresoPreferencial() As Double
        Get
            Return mdblIngresoPreferencial
        End Get
        Set(ByVal value As Double)
            mdblIngresoPreferencial = value
        End Set
    End Property
    Public Property IngresoGeneral() As Double
        Get
            Return mdblIngresoGeneral
        End Get
        Set(ByVal value As Double)
            mdblIngresoGeneral = value
        End Set
    End Property
    Public Property Vueltas() As Double
        Get
            Return mdblVueltas
        End Get
        Set(ByVal value As Double)
            mdblVueltas = value
        End Set
    End Property
    Public Property Liquidacion() As Double
        Get
            Return mdblLiquidacion
        End Get
        Set(ByVal value As Double)
            mdblLiquidacion = value
        End Set
    End Property
    Public Property Importe01() As Double
        Get
            Return mdblImporte01
        End Get
        Set(ByVal value As Double)
            mdblImporte01 = value
        End Set
    End Property
    Public Property Importe02() As Double
        Get
            Return mdblImporte02
        End Get
        Set(ByVal value As Double)
            mdblImporte02 = value
        End Set
    End Property
    Public Property Importe03() As Double
        Get
            Return mdblImporte03
        End Get
        Set(ByVal value As Double)
            mdblImporte03 = value
        End Set
    End Property
    Public Property Importe04() As Double
        Get
            Return mdblImporte04
        End Get
        Set(ByVal value As Double)
            mdblImporte04 = value
        End Set
    End Property
    Public Property Importe05() As Double
        Get
            Return mdblImporte05
        End Get
        Set(ByVal value As Double)
            mdblImporte05 = value
        End Set
    End Property
    Public Property Texto01 As String
        Get
            Return mstrTexto01
        End Get
        Set(value As String)
            mstrTexto01 = value
        End Set
    End Property
    Public Property Texto02 As String
        Get
            Return mstrTexto02
        End Get
        Set(value As String)
            mstrTexto02 = value
        End Set
    End Property
    Public Property Texto03 As String
        Get
            Return mstrTexto03
        End Get
        Set(value As String)
            mstrTexto03 = value
        End Set
    End Property
    Public Property Texto04 As String
        Get
            Return mstrTexto04
        End Get
        Set(value As String)
            mstrTexto04 = value
        End Set
    End Property
    Public Property Texto05 As String
        Get
            Return mstrTexto05
        End Get
        Set(value As String)
            mstrTexto05 = value
        End Set
    End Property

    Public Sub New()
        mintIdLiquidacion = 0
        mdatFecha = Now()
        mintIdLiquidador = 0
        mstrCodigoLiquidador = ""
        mstrNombreLiquidador = ""
        mintIdOperador = 0
        mstrCodigoOperador = ""
        mstrNombreOperador = ""
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdRuta = 0
        mstrNombreRuta = ""
        mintTipoLiquidacion = 0
        mstrSerie = ""
        mdblNumeracionInicial = 0
        mdblNumeracionFinal = 0
        mdblTotalBoletos = 0
        mdblPreferencial = 0
        mdblGeneral = 0
        mdblIngresoPreferencial = 0
        mdblIngresoGeneral = 0
        mdblVueltas = 0
        mdblLiquidacion = 0
        mdblImporte01 = 0
        mdblImporte02 = 0
        mdblImporte03 = 0
        mdblImporte04 = 0
        mdblImporte05 = 0
        mstrTexto01 = ""
        mstrTexto02 = "0"
        mstrTexto03 = ""
        mstrTexto04 = ""
        mstrTexto05 = ""
    End Sub
    Public Sub Guardar()
        Dim intRetVal As Integer

        intRetVal = mintIdLiquidacion

        If intRetVal = 0 Then
            Insertar()
        Else
            Actualizar()
        End If

    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Liquidacion " & _
        " WHERE IdLiquidacion=" & mintIdLiquidacion & ""

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mdatFecha = rdBuscar("Fecha")
            mintIdLiquidador = rdBuscar("IdLiquidador")
            mstrNombreLiquidador = rdBuscar("NombreLiquidador").ToString.Trim
            mintIdOperador = rdBuscar("IdOperador")
            mstrCodigoLiquidador = rdBuscar("CodigoLiquidador").ToString.Trim
            mstrNombreOperador = rdBuscar("NombreOperador").ToString.Trim
            mintIdAutobus = rdBuscar("IdAutobus")
            mstrCodigoOperador = rdBuscar("CodigoOperador").ToString.Trim
            mstrNoEconomico = rdBuscar("NoEconomico").ToString.Trim
            mintIdRuta = rdBuscar("IdRuta")
            mstrNombreRuta = rdBuscar("NombreRuta").ToString.Trim
            mintTipoLiquidacion = rdBuscar("TipoLiquidacion")
            mstrSerie = rdBuscar("Serie").ToString.Trim
            mdblNumeracionInicial = rdBuscar("NumeracionInicial")
            mdblNumeracionFinal = rdBuscar("NumeracionFinal")
            mdblTotalBoletos = rdBuscar("TotalBoletos")
            mdblPreferencial = rdBuscar("Preferencial")
            mdblGeneral = rdBuscar("General")
            mdblIngresoPreferencial = rdBuscar("IngresoPreferencial")
            mdblIngresoGeneral = rdBuscar("IngresoGeneral")
            mdblVueltas = rdBuscar("Vueltas")
            mdblLiquidacion = rdBuscar("Liquidacion")
            mdblImporte01 = rdBuscar("Importe01")
            mdblImporte02 = rdBuscar("Importe02")
            mdblImporte03 = rdBuscar("Importe03")
            mdblImporte04 = rdBuscar("Importe04")
            mdblImporte05 = rdBuscar("Importe05")
            mstrTexto01 = rdBuscar("Texto01").ToString.Trim
            mstrTexto02 = rdBuscar("Texto02").ToString.Trim
            mstrTexto03 = rdBuscar("Texto03").ToString.Trim
            mstrTexto04 = rdBuscar("Texto04").ToString.Trim
            mstrTexto05 = rdBuscar("Texto05").ToString.Trim

        Else

            mdatFecha = Now()
            mintIdLiquidador = 0
            mstrNombreLiquidador = ""
            mintIdOperador = 0
            mstrCodigoLiquidador = ""
            mstrCodigoOperador = ""
            mstrNombreOperador = ""
            mintIdAutobus = 0
            mstrNoEconomico = ""
            mintIdRuta = 0
            mstrNombreRuta = ""
            mintTipoLiquidacion = 0
            mstrSerie = ""
            mdblNumeracionInicial = 0
            mdblNumeracionFinal = 0
            mdblTotalBoletos = 0
            mdblPreferencial = 0
            mdblGeneral = 0
            mdblIngresoPreferencial = 0
            mdblIngresoGeneral = 0
            mdblVueltas = 0
            mdblLiquidacion = 0
            mdblImporte01 = 0
            mdblImporte02 = 0
            mdblImporte03 = 0
            mdblImporte04 = 0
            mdblImporte05 = 0
            mstrTexto01 = ""
            mstrTexto02 = "0"
            mstrTexto03 = ""
            mstrTexto04 = ""
            mstrTexto05 = ""
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Liquidacion (" & _
                            "Fecha," & _
                            "IdLiquidador," & _
                            "CodigoLiquidador," & _
                            "NombreLiquidador," & _
                            "IdOperador," & _
                            "CodigoOperador," & _
                            "NombreOperador," & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdRuta," & _
                            "NombreRuta," & _
                            "TipoLiquidacion," & _
                            "Serie," & _
                            "NumeracionInicial," & _
                            "NumeracionFinal," & _
                            "TotalBoletos," & _
                            "Preferencial," & _
                            "General," & _
                            "IngresoPreferencial," & _
                            "IngresoGeneral," & _
                            "Vueltas," & _
                            "Liquidacion," & _
                            "Importe01," & _
                            "Importe02," & _
                            "Importe03," & _
                            "Importe04," & _
                            "Importe05," & _
                            "Texto01," & _
                            "Texto02," & _
                            "Texto03," & _
                            "Texto04," & _
                            "Texto05) " & _
                            "VALUES (" & _
                            "@Fecha," & _
                            "@IdLiquidador," & _
                            "@CodigoLiquidador," & _
                            "@NombreLiquidador," & _
                            "@IdOperador," & _
                            "@CodigoOperador," & _
                            "@NombreOperador," & _
                            "@IdAutobus," & _
                            "@NoEconomico," & _
                            "@IdRuta," & _
                            "@NombreRuta," & _
                            "@TipoLiquidacion," & _
                            "@Serie," & _
                            "@NumeracionInicial," & _
                            "@NumeracionFinal," & _
                            "@TotalBoletos," & _
                            "@Preferencial," & _
                            "@General," & _
                            "@IngresoPreferencial," & _
                            "@IngresoGeneral," & _
                            "@Vueltas," & _
                            "@Liquidacion," & _
                            "@Importe01," & _
                            "@Importe02," & _
                            "@Importe03," & _
                            "@Importe04," & _
                            "@Importe05," & _
                            "@Texto01," & _
                            "@Texto02," & _
                            "@Texto03," & _
                            "@Texto04," & _
                            "@Texto05) " & _
                            " SELECT SCOPE_IDENTITY()"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("IdLiquidador", mintIdLiquidador)
        Command.Parameters.AddWithValue("CodigoLiquidador", mstrCodigoLiquidador)
        Command.Parameters.AddWithValue("NombreLiquidador", mstrNombreLiquidador)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("CodigoOperador", mstrCodigoOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdRuta", mintIdRuta)
        Command.Parameters.AddWithValue("NombreRuta", mstrNombreRuta)
        Command.Parameters.AddWithValue("TipoLiquidacion", mintTipoLiquidacion)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("NumeracionInicial", mdblNumeracionInicial)
        Command.Parameters.AddWithValue("NumeracionFinal", mdblNumeracionFinal)
        Command.Parameters.AddWithValue("TotalBoletos", mdblTotalBoletos)
        Command.Parameters.AddWithValue("Preferencial", mdblPreferencial)
        Command.Parameters.AddWithValue("General", mdblGeneral)
        Command.Parameters.AddWithValue("IngresoPreferencial", mdblIngresoPreferencial)
        Command.Parameters.AddWithValue("IngresoGeneral", mdblIngresoGeneral)
        Command.Parameters.AddWithValue("Vueltas", mdblVueltas)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Importe01", mdblImporte01)
        Command.Parameters.AddWithValue("Importe02", mdblImporte02)
        Command.Parameters.AddWithValue("Importe03", mdblImporte03)
        Command.Parameters.AddWithValue("Importe04", mdblImporte04)
        Command.Parameters.AddWithValue("Importe05", mdblImporte05)
        Command.Parameters.AddWithValue("Texto01", mstrTexto01)
        Command.Parameters.AddWithValue("Texto02", mstrTexto02)
        Command.Parameters.AddWithValue("Texto03", mstrTexto03)
        Command.Parameters.AddWithValue("Texto04", mstrTexto04)
        Command.Parameters.AddWithValue("Texto05", mstrTexto05)

        cnConn.Open()
        IdLiquidacion = Convert.ToInt32(Command.ExecuteScalar)

        If IdLiquidacion > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update Liquidacion Set " & _
                    "Fecha=@Fecha," & _
                    "IdLiquidador=@IdLiquidador," & _
                    "CodigoLiquidador=@CodigoLiquidador," & _
                    "NombreLiquidador=@NombreLiquidador," & _
                    "IdOperador=@IdOperador," & _
                    "CodigoOperador=@CodigoOperador," & _
                    "NombreOperador=@NombreOperador," & _
                    "IdAutobus=@IdAutobus," & _
                    "NoEconomico=@NoEconomico," & _
                    "IdRuta=@IdRuta," & _
                    "NombreRuta=@NombreRuta," & _
                    "TipoLiquidacion=@TipoLiquidacion," & _
                    "Serie=@Serie," & _
                    "NumeracionInicial=@NumeracionInicial," & _
                    "NumeracionFinal=@NumeracionFinal," & _
                    "TotalBoletos=@TotalBoletos," & _
                    "Preferencial=@Preferencial," & _
                    "General=@General," & _
                    "IngresoPreferencial=@IngresoPreferencial," & _
                    "IngresoGeneral=@IngresoGeneral," & _
                    "Vueltas=@Vueltas," & _
                    "Liquidacion=@Liquidacion," & _
                    "Importe01=@Importe01," & _
                    "Importe02=@Importe02," & _
                    "Importe03=@Importe03," & _
                    "Importe04=@Importe04," & _
                    "Importe05=@Importe05," & _
                    "Texto01=@Texto01," & _
                    "Texto02=@Texto02," & _
                    "Texto03=@Texto03," & _
                    "Texto04=@Texto04," & _
                    "Texto05=@Texto05 " & _
                    "Where IdLiquidacion=@IdLiquidacion"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("IdLiquidacion", mintIdLiquidacion)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("IdLiquidador", mintIdLiquidador)
        Command.Parameters.AddWithValue("CodigoLiquidador", mstrCodigoLiquidador)
        Command.Parameters.AddWithValue("NombreLiquidador", mstrNombreLiquidador)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("CodigoOperador", mstrCodigoOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdRuta", mintIdRuta)
        Command.Parameters.AddWithValue("NombreRuta", mstrNombreRuta)
        Command.Parameters.AddWithValue("TipoLiquidacion", mintTipoLiquidacion)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("NumeracionInicial", mdblNumeracionInicial)
        Command.Parameters.AddWithValue("NumeracionFinal", mdblNumeracionFinal)
        Command.Parameters.AddWithValue("TotalBoletos", mdblTotalBoletos)
        Command.Parameters.AddWithValue("Preferencial", mdblPreferencial)
        Command.Parameters.AddWithValue("General", mdblGeneral)
        Command.Parameters.AddWithValue("IngresoPreferencial", mdblIngresoPreferencial)
        Command.Parameters.AddWithValue("IngresoGeneral", mdblIngresoGeneral)
        Command.Parameters.AddWithValue("Vueltas", mdblVueltas)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Importe01", mdblImporte01)
        Command.Parameters.AddWithValue("Importe02", mdblImporte02)
        Command.Parameters.AddWithValue("Importe03", mdblImporte03)
        Command.Parameters.AddWithValue("Importe04", mdblImporte04)
        Command.Parameters.AddWithValue("Importe05", mdblImporte05)
        Command.Parameters.AddWithValue("Texto01", mstrTexto01)
        Command.Parameters.AddWithValue("Texto02", mstrTexto02)
        Command.Parameters.AddWithValue("Texto03", mstrTexto03)
        Command.Parameters.AddWithValue("Texto04", mstrTexto04)
        Command.Parameters.AddWithValue("Texto05", mstrTexto05)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
    Public Sub ActualizarParaVisor()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update Liquidacion Set " & _
                    "Importe03=@Importe03," & _
                    "Texto02=@Texto02," & _
                    "Texto03=@Texto03 " & _
                    "Where IdLiquidacion=@IdLiquidacion"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("IdLiquidacion", mintIdLiquidacion)
        Command.Parameters.AddWithValue("Importe03", mdblImporte03)
        Command.Parameters.AddWithValue("Texto02", mstrTexto02)
        Command.Parameters.AddWithValue("Texto03", mstrTexto03)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
